home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Communications Toolbox / Get Tool Config / Source / GetToolConfig.c
Encoding:
C/C++ Source or Header  |  1997-02-19  |  3.2 KB  |  119 lines  |  [TEXT/CWIE]

  1. /*
  2.     Get Tool Config
  3.     ©1991 Apple Computer Inc.
  4.     By    Apple Developer Tech Support
  5.     
  6.     Description:
  7.         This q&d allows one to accumulate into a TEXT file the config strings 
  8.         of Connection Tools that have been configured with CMChoose.
  9.     
  10.     Build Instructions:
  11.         Used with THINK C v5.0, project setup:
  12.             seg1: GetToolConfig.c, MacTraps, CommToolbox
  13.             seg2: ANSI
  14.  
  15.     Change History:
  16.     
  17.     8/10/91        Godfrey DiGiorgi    created this bugger from some existing source lying about
  18.     8/30/91     Godfrey DiGiorgi    fixed it up to be useful
  19. */
  20. #include <Traps.h>
  21. #include <stdio.h>
  22. #include <CommResources.h>
  23. #include <Connections.h>
  24. #include <Memory.h>
  25. #include <TextUtils.h>
  26.  
  27. // function prototypes
  28. void main(void);
  29.  
  30. void main() {
  31.     short           procID;
  32.     ConnHandle      connection;
  33.     CMBufferSizes   bufSizes;
  34.     OSErr           err;
  35.     Str255          toolName;
  36.     Point           where;
  37.     short           result;
  38.     Ptr             configStream;
  39.     FILE*           fp;
  40.     
  41.     // putting something into TTY window initializes QD globals, etc.
  42.     printf("•• running Get Tool Config program ••\n\n");
  43.     
  44.     // initialize CTB and managers
  45.     if (NGetTrapAddress(_CommToolboxDispatch, OSTrap) ==
  46.         NGetTrapAddress(_Unimplemented, OSTrap)) {
  47.         printf("•• CTB Not available ••\n");
  48.         return;
  49.     }
  50.     if (noErr != InitCRM()) {
  51.         printf("•• CTB Available but InitCRM failed. ••\n");
  52.         return;
  53.     }
  54.     if (noErr != InitCTBUtilities()) {
  55.         printf("•• CTB Available: InitCTBUtilities Fail. ••\n");
  56.         return;
  57.     }
  58.     if (cmNoTools == InitCM()) {
  59.         printf("•• CTB Available: No connection tools found. ••\n");
  60.         return;
  61.     }
  62.     
  63.     // get a Connection Tool name
  64.     err = CRMGetIndToolName('cbnd',1,toolName);
  65.     if (err != noErr) {
  66.         printf("•• CRMGetIndToolName failed... no Conn Tool available ?!?!? ••\n");
  67.         return;
  68.     }
  69.     // get a resource ID for it
  70.     procID = CMGetProcID(toolName);
  71.     if (-1 == procID) {
  72.         printf("•• CMGetProcID: No 'Apple (ISDN) Serial Tool'. ••\n");
  73.         return;
  74.     }
  75.     
  76.     // init the CMBufferSizes variable so that Tool will init with defaults
  77.     bufSizes[cmDataIn] = 0;
  78.     bufSizes[cmDataOut] = 0;
  79.     bufSizes[cmCntlIn] = 0;
  80.     bufSizes[cmCntlOut] = 0;
  81.     bufSizes[cmAttnIn] = 0;
  82.     bufSizes[cmAttnOut] = 0;
  83.     
  84.     // now get a conn record set up 
  85.     connection = CMNew(procID, cmData|cmNoMenus|cmQuiet, bufSizes, 0, 0);
  86.     if (connection == nil) {
  87.         printf("•• CMNew: Can't create a CTB connection record. ••\n");
  88.         return;
  89.     }
  90.     
  91.     // CMChoose Dialog has to hang off this point (global coordinates)
  92.     SetPt(&where,20,40);
  93.     // now do CMChoose et al:
  94.     result = CMChoose(&connection,where,NULL);
  95.     if ((result == chooseOKMajor) || (result == chooseOKMinor)) {
  96.         configStream = CMGetConfig(connection);
  97.         if (configStream == NULL) {
  98.             printf("CMGetConfig failed\n\n");
  99.         } else {
  100.             CMGetToolName((**connection).procID,toolName);
  101.             p2cstr(toolName);
  102.             printf("• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
  103.             fp = fopen("Tool Configs","a");
  104.             if (fp != NULL) {
  105.                 fprintf(fp,"• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
  106.                 fclose(fp);
  107.                 printf("•• Configuration string info appended to file 'Tool Configs'. ••\n\n");
  108.             } else {
  109.                 printf("•• Output file could not be opened. ••\n");
  110.             }
  111.             DisposePtr(configStream);
  112.         }
  113.     } else {
  114.         printf("•• CMChoose failed. ••\n");
  115.     }
  116.     CMDispose(connection);
  117.     printf("•• closing Get Tool Config program ••\n\n");
  118. }
  119.